package com.battery.web.controller.system.battery;

import java.util.List;

import com.battery.system.domain.BO.PreCostBO;
import com.battery.system.domain.VO.PreCostVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.battery.common.annotation.Log;
import com.battery.common.enums.BusinessType;
import com.battery.system.domain.PreCost;
import com.battery.system.service.battery.IPreCostService;
import com.battery.common.core.controller.BaseController;
import com.battery.common.core.domain.AjaxResult;
import com.battery.common.utils.poi.ExcelUtil;
import com.battery.common.core.page.TableDataInfo;

/**
 * 预付费记录Controller
 *
 * @author battery
 * @date 2021-06-20
 */
@Controller
@RequestMapping("/system/preCost")
public class PreCostController extends BaseController {
    private String prefix = "system/preCost";

    @Autowired
    private IPreCostService preCostService;

    @RequiresPermissions("system:preCost:view")
    @GetMapping()
    public String preCost() {
        return prefix + "/preCost";
    }

    /**
     * 查询预付费记录列表
     */
    @RequiresPermissions("system:preCost:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PreCostBO preCostBO) {
        startPage();
//        List<PreCost> list = preCostService.selectPreCostList(preCost);
        List<PreCostVO> list = preCostService.selectPreCostVOList(preCostBO);
        return getDataTable(list);
    }

    /**
     * 导出预付费记录列表
     */
    @RequiresPermissions("system:preCost:export")
    @Log(title = "预付费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PreCost preCost) {
        List<PreCost> list = preCostService.selectPreCostList(preCost);
        ExcelUtil<PreCost> util = new ExcelUtil<PreCost>(PreCost.class);
        return util.exportExcel(list, "preCost");
    }

    /**
     * 新增预付费记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存预付费记录
     */
    @RequiresPermissions("system:preCost:add")
    @Log(title = "预付费记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PreCost preCost) {
        return toAjax(preCostService.insertPreCost(preCost));
    }

    /**
     * 修改预付费记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        PreCost preCost = preCostService.selectPreCostById(id);
        mmap.put("preCost", preCost);
        return prefix + "/edit";
    }

    /**
     * 修改保存预付费记录
     */
    @RequiresPermissions("system:preCost:edit")
    @Log(title = "预付费记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PreCost preCost) {
        return toAjax(preCostService.updatePreCost(preCost));
    }

    /**
     * 删除预付费记录
     */
    @RequiresPermissions("system:preCost:remove")
    @Log(title = "预付费记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(preCostService.deletePreCostByIds(ids));
    }
}
